using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class SupplierBLL
    {
        SupplierDal supplierDal = new SupplierDal();

        public List<SupplierReturnModel> GetList(SupplierSearchModel ssm, Pagination page, TokenModel token)
        {
            return supplierDal.GetList(ssm, page, token);
        }

        public Guid SaveSupplier(Supplier supplier, TokenModel token)
        {
            Guid SupplierID = supplier.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (supplier != null && supplier.id != Guid.Empty)
            {
                //修改
                isSuccess = supplierDal.UpdateModel(supplier) > 0;

            }
            else
            {
                //新增
                supplier.addTime = curTime;
                supplier.addUserID = token.UID;
                Supplier supplierInfo = supplierDal.AddModel(supplier);
                SupplierID = supplierInfo.id;

            }

            return SupplierID;
        }

        public SupplierReturnModel GetSupplierByID(Guid id)
        {
            SupplierReturnModel supplierModel = new SupplierReturnModel();
            Supplier supplier = supplierDal.FindModel(c => c.id == id);
            supplierModel = ClassHelper.ParentCopyToChild<Supplier, SupplierReturnModel>(supplier);

            return supplierModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return supplierDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
